<?php
// $Id$

/**
 * Controller_Admin_Web 控制器
 */
class Controller_Admin_videoplate extends Controller_Abstract {
	
	/**
	 * 客户端顶部广告
	 */
	function actionIndex()
	{
		$this->_context->orderField='weight';
		$this->_context->orderDirection='desc';
		$this->union_table = videoplate::meta();
		$this->lists(array("acct_id"=>$_SESSION['acct']['id']));
	}
	 
	/**
	 * 讲师设置
	 */
	 
	function actionAdd() {
	    //设置要操作的表单，并设置自动插入方式
	    $this->union_table = videoplate::meta ();
	    
	     
 
	    //这里面会自动将get方式获取的参数传递到表单里面去的
	    if ($this->_context->isGET ()) {
	    	if($this->_context->id){
	    		$plate = videoplate::find("id = ".$this->_context->id)->getOne();
	    		$this->_view ['plate'] = $plate;
	    	}
	    } else {

			if(!empty($this->_context->id)){
				$plate = videoplate::find("id = ".$this->_context->id)->getOne();
				$plate->name=trim($this->_context->name);
				$plate->displayway=intval($this->_context->displayway);
				$plate->weight=intval($this->_context->weight);
				$video_id = '';
				if(!empty($this->_context->video_id)){
				    $video_id = $this->_context->video_id;
				    $plate->video_id= implode(',',$video_id);
				}else{
				    $plate->video_id= '';
				}
	             
				

				$plate->save(0,'update');
			}else{
				$plate = new videoplate();
				$plate->acct_id=$_SESSION['acct']['id'];
				$plate->name=trim($this->_context->name);
				$plate->displayway=intval($this->_context->displayway);
				$plate->weight=intval($this->_context->weight);
				$plate->video_id=implode(',',$this->_context->video_id);
				$plate->save(0,'create');
			}
	        //记录日志
	        if(!$_POST['id'])	{
	            Syslog::logs ( '添加首页模块,id :' . $plate->id );
	        }else{
	            Syslog::logs ( '编辑首页模块,id :' . $plate->id );
	        }
	         
	        $this->_context->forwardUrl = url("videoplate/index");
	        $this->success('编辑成功');
	    }
	     
	}
	 
	/**
	 * 删除讲师
	 */
	function actionDel() {
	     Syslog::logs("删除首页模块，ID：".print_r($this->_context->ids,true));
	     $this->union_table = videoplate::meta();
	     $this->delete(array('id'=>$this->_context->ids));
	}


}


